<!DOCTYPE HTML>
<html>
  <head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/about.css"/>
    <script type="text/javascript" src="../js/jquery-1.4.2.js"></script>
    <script type="text/javascript" src="../js/base.js"></script>
    <script type="text/javascript" src="../js/ajax_post.js"></script>
    <style type="text/css">
      #madnUserTa{
      width:80%;
      height:300px;
      }
    </style>
  </head>
  <body>
    <div class="bar">监控面板</div>
    <div class="title"><span id="wizard2Span"></span>MADN管理</div>
    <div class="form_container">
      <div id="Tips"><div></div><cite></cite></div>	 
      <hr/>
      <form id="ip_form" onsubmit="return false">
        <div class="tabs">
          <div id="tabs_content">
            <div><b>维护MADN的用户列表</b></div>
          </div>
        </div>
        <hr/>
        <ul id="ipForn" style="width:95%;">
          <li>
            <span id="hostIp"></span>
          </li>
          <li>
            在下面的文本域内修改MADN用户的信息，注意保持如下格式(用户,是否启用,Bucket,私钥Id,私钥;),多个Buckets用|分隔
          </li>
          <li>
            >> 注意,目前版本不支持一个用户有多个key pair
          </li>
          <li>
            <textarea id="madnUserTa" spellcheck="false"></textarea>
          </li>
          <li>
            <input type="button" value="更新" id="updateMadnUserBtn" />
          </li>
        </ul>
      </form>
    </div>
    <script>
    </script>
  </body>
  <script>
    function reqMdnUser() {
      var version=url_params("version");
      var domain=domainURI(document.location.href); 
      get_data_ajax("http://"+domain+"/mmsapi"+version+"/get/mdndeliver_setting/@self","#madnUserTa","loading_small.gif",get_madn_user_Callback) 
    }

    function get_madn_user_Callback(json, textStatus, jqXHR) { // 获取请求
      var out=''; 
        if (jqXHR.status==200) {
          $.each(json,function(key,value) {
          console.log(key)
          console.log(value)
          out=out+key+','+value[0]+','+value[1]+','+value[2]+','+value[3]+';'+"\n";
          });
          $('#madnUserTa').html(out)
       }
    }

    $(document).ready(function(){
      reqMdnUser();
    } )

function base64encode(str) {
     var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
     var out, i, len;
     var c1, c2, c3;

     len = str.length;
     i = 0;
     out = "";
     while(i < len) {
         c1 = str.charCodeAt(i++) & 0xff;
         if(i == len)
         {
             out += base64EncodeChars.charAt(c1 >> 2);
             out += base64EncodeChars.charAt((c1 & 0x3) << 4);
             out += "==";
             break;
         }
         c2 = str.charCodeAt(i++);
         if(i == len)
         {
             out += base64EncodeChars.charAt(c1 >> 2);
             out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
             out += base64EncodeChars.charAt((c2 & 0xF) << 2);
             out += "=";
             break;
         }
         c3 = str.charCodeAt(i++);
         out += base64EncodeChars.charAt(c1 >> 2);
         out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
         out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
         out += base64EncodeChars.charAt(c3 & 0x3F);
     }
     return out;
}

    $("#updateMadnUserBtn").bind('click', function(){
      var domain=domainURI(document.location.href);
      var version=url_params('version');
      var ds={'data':base64encode($('#madnUserTa').val())}
      console.log(ds)
      $.ajax({
        type: "post",
        url : "http://"+domain+"/mmsapi"+version+"/update/mdndeliver_setting/@self",
        async: false,
        data: ds,
        success: function(json, textStatus, jqXHR){//如果调用php成功
          if(jqXHR.status==200 || jqXHR.status==205){
            Tips("complete","MADN用户设置成功!");
          }
        },
        error: function(jqXHR, textStatus, errorThrown){
                 switch(jqXHR.status){
                 case 400 : Tips("alert" ,"数据未找到");break;
                 case 500 : Tips("alert" ,"服务器出错");break;
                 }
               }
      });
    });
    </script>
</html>
